This article describes the aspects and parts of the Rapid Toolkit for Sparkplug data model that are used when developing providers (Sparkplug edge nodes and devices).
Sparkplug edge node is a component in Sparkplug system that communicates with the broker using the Sparkplug protocol and topic namespace, and acts as a gateway to its underlying system (such as PLC, sensors, internal process variables, etc.). In Rapid Toolkit for Sparkplug, a Sparkplug edge node is represented by an instance of the EasySparkplugEdgeNode Class.
Your code create an instance of the EasySparkplugEdgeNode Class, and uses its properties and methods to define the edge node parameters, contents, and behavior.
The EasySparkplugEdgeNode Class has various properties that can be used to influence how the edge node works. The most important ones are explained below.
Some edge node object properties can be pre-set using the object constructor (see below). However, you can always create the edge node object empty (using the default constructor), and then set its properties by assigning to them.
An instance of the EasySparkplugEdgeNode Class is normally created by calling its constructor. The default constructor (with no parameters) creates the edge node object with all defaults. There are various constructor overloads that allow you to initialize the newly created edge node object with certain most important properties (such as the MQTT broker URL, and the Sparkplug group ID and edge node ID) upfront. The various ways of constructing the edge node object are illustrated in the example below, and in the examples listed in the "See Also" section at the bottom of the page..
A common way of constructing the EasySparkplugEdgeNode Class instance is to use the constructor that takes the URL of the MQTT broker endpoint, and the Sparkplug group ID and edge node ID as arguments (this is illustrated in the example code further below).
Example
Sparkplug device (a device/sensor connected to the Sparkplug edge node) is represented by the SparkplugDevice Class in Rapid Toolkit for Sparkplug.
A Sparkplug device is typically a sensor, actuator, or other endpoint that communicates its data through a Sparkplug edge node. Devices do not connect directly to the MQTT broker; instead, they internally connect to an edge node, which aggregates and forwards their data using the Sparkplug protocol. The edge node manages the lifecycle, state, and data of its devices, ensuring reliable and structured communication with the broker.
Note that the presence of one or more devices in the Sparkplug edge node is optional. The edge node may have no devices, and only expose metric on the edge node itself.
The Sparkplug device ID is stored in the DeviceId Property. The collection of Sparkplug metrics that this device publishes is contained in the Metrics Property of the device. You can add or remove your metrics in this collection.
You can separately create the device object and then add it to the Devices collection of the edge node. Alternatively, you can use the static CreateIn Method, which combines creation of the device object, setting its device ID, and adding it into the parent edge node, in one method call.
Both the Sparkplug edge node object (EasySparkplugEdgeNode Class) and the Sparkplug device (SparkplugDevice Class) described above are Sparkplug producers, and share many common characteristics, some of which are described here.
Each Sparkplug producer (edge node or device) is associated with a data source. Data source is an abstract concept, and it can be practically anything that the edge or device communicates with. Rapid Toolkit for Sparkplug does not prescribe how the communication with the data source should be done. Handling the communication is the primary task of the code you need to write when using Rapid Toolkit for Sparkplug to create Sparkplug edge nodes. Rapid Toolkit for Sparkplug, however, defines an interface to the data source with regard to its connections and disconnections. This is because the Sparplug specification prescribes the proper behavior of Sparkplug edge nodes and devices related to the data source status.
Also, each Sparkplug producer can adjust its behavior to the state of its Sparkplug environment. The producer's data source can be connected whenever the edge node or device is started, but also depending on other factors - such as whether the Sparkplug system (MQTT broker) is successfully connected, or whether the primary host application (when configured) for the edge node is currently online. This is controlled by the DataSourceConnectionMode Property on the edge node or device.
provides periodic polling for the metrics on the edge node or device with an interval specified by the PublishingInterval Property. You can also choose to disable the polling and report any changed data from your code explicitly, by turning on the ReportByException Property.
The Sparkplug metric is a data point in the Sparkplug system, and is represented by the SparkplugMetric Class in Rapid Toolkit for Sparkplug. These also represent tags in classic SCADA systems. The metric contains data (value and timestamp) that is published to Sparkplug, and/or can be set from Sparkplug (by Sparkplug commands).
Each metric has a name (a string; Name Property). The name must be unique among the metrics in the parent (edge node, or a device).
If your implementation needs it, the metric can be associated with any object you like. This is done using the State Property of the metric.
You can separately create the metric object and then add it to the Metrics collection of the edge node or device. Alternatively, you can use the static CreateIn Method, which combines creation of the metric object, setting its name, and adding it into the parent edge node or device, in one method call.
After the initial creation of the metric, it is then common to configure it further, as described in Sparkplug Metric Configuration.
Example
Rapid Toolkit for Sparkplug uses interfaces where appropriate. This means that in many cases, when we refer to member of Rapid Toolkit for Sparkplug objects, these members are actually defined by some interface that the object implements. Specifically, for example:
Consequently, at many places, Rapid Toolkit for Sparkplug uses the interface types for method arguments and properties, instead of the concrete classes.
The classes and interfaces contain only methods that are necessary to express the required object functionality. The remaining methods (and method overloads) simply build on these "core" methods, and are implemented as extension methods on the interfaces or classes. In most languages (certainly in C# and VB.NET), this design leads to the same syntax as if all the methods were implemented directly on the "core" concrete object.
Sparkplug is a trademark of Eclipse Foundation, Inc. "MQTT" is a trademark of the OASIS Open standards consortium. Other related terms are trademarks of their respective owners. Any use of these terms on this site is for descriptive purposes only and does not imply any sponsorship, endorsement or affiliation.